#import "ArleneNode.h"

#import <UIKit/UIKit.h>

@class ArleneTableSection;
@class ArleneTableRow;

typedef NS_ENUM(NSUInteger, ArleneTableRowState) {
    ArleneTableRowStateDefault,
    ArleneTableRowStateOpen
};

NS_ASSUME_NONNULL_BEGIN

/**
 The Click Event, you can also use didSelect method for process events intensively
 *
 */
typedef void (^SelectRowEvent) (__kindof UITableView *tableView, __kindof ArleneTableRow *row, __kindof UITableViewCell *cell, NSIndexPath *indexPath);

@interface ArleneTableRow : ArleneNode

@property (nonatomic, copy) SelectRowEvent selectRowEvent;
@property (nonatomic, assign, readwrite) CGFloat cellHeight;
@property (nonatomic, assign) ArleneTableRowState state;
/**
 *  return 'YES' if you want autojust cell height, strongly recommended(with autolayout)
 *
 */
- (BOOL)autoAdjustCellHeight;

- (__kindof UITableViewCell *)cellForTableViewAutoAdjust;

/**
 * @required
 */
- (NSString *)reuseIdentifier;

/**
 * @required
 */
- (__kindof UITableViewCell *)createCellForAutoAdjustedTableViewCell;

/**
 *  when computed constraints changed, call this.
 *  @waring already displayed cell won't auto height. need reload row
 *  @see autoAdjustCellHeight
 */
- (void)invalidateAutoCellHeight:(ArleneTableRowState)state;


/**
 *  Creates a new cell that the table view row manages.
 *
 *  @return The newly created cell that the row manages.
 */
- (__kindof UITableViewCell *)cellForTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath;

/**
 Do the specific things for cell
 *
 */
- (void)updateCell:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath;

- (nullable NSIndexPath *)indexPath;

/**
 * If not autolayout for whole cell, return this view. Default is nil
 */
- (nullable UIView *)autoLayoutView;

/**
 * optional
 */
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;

/**
 * optional
 */
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
/**
 * optional
 */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath;

- (CGFloat)estimatedHeight;

/**
 * Override point
 */
- (void)rowWillAddToSection:(ArleneTableSection *)section;
- (void)rowDidAddToSection:(ArleneTableSection *)section;

@end

NS_ASSUME_NONNULL_END
